/**
 * 
 */
package com.wrsr.examsys.card.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.wrsr.examsys.base.dao.BaseDao;
import com.wrsr.examsys.base.service.impl.BaseServiceImpl;
import com.wrsr.examsys.card.service.CardService;
import com.wrsr.examsys.domain.Card;

/**
 * @author <a href="mailto:2397431783@qq.com">wangruishun</a>
 *
 *         2015年5月8日
 */
@Service("cardService")
public class CardServiceImpl extends BaseServiceImpl<Card> implements
		CardService {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.wrsr.examsys.base.service.impl.BaseServiceImpl#setDao(com.wrsr.examsys
	 * .base.dao.BaseDao)
	 */
	@SuppressWarnings("rawtypes")
	@Override
	@Resource(name = "cardDao")
	public void setDao(BaseDao dao) {
		super.setDao(dao);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.wrsr.examsys.card.service.CardService#getTotal()
	 */
	@Override
	public Integer getTotal() {
		String hql = "from Card c where c.deleteFlag=?";
		List<Card> cards = super.findEntityByHQL(hql, 1);
		if (cards == null || cards.isEmpty()) {
			return 0;
		} else {
			return cards.size();
		}

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.wrsr.examsys.card.service.CardService#getCardByPage(int, int)
	 */
	@Override
	public List<Card> getCardByPage(int offset, int length) {
		return super.getListForPage("from Card c where  c.deleteFlag=1 order by c.cardId desc",
				offset, length);

	}

	/* (non-Javadoc)
	 * @see com.wrsr.examsys.card.service.CardService#getCardListNotRead(java.lang.String, int, int)
	 */
	@Override
	public List<Card> getCardListNotRead(String fromId, int offset, int length) {
		List<Card> cards=super.getListForPage("from Card c where  c.deleteFlag=1 and c.fromId='"+fromId+"' order by c.cardId desc",
					offset, length);
		
		 return cards;
	}

	/* (non-Javadoc)
	 * @see com.wrsr.examsys.card.service.CardService#getNotReadTotal()
	 */
	@Override
	public Integer getNotReadTotal(String fromId) {
		String hql = "from Card c where c.deleteFlag=? and c.fromId=?";
		List<Card> cards = super.findEntityByHQL(hql, 1,fromId);
		if (cards == null || cards.isEmpty()) {
			return 0;
		} else {
			return cards.size();
		}

	}
	

}
